
#include "ExpItemFormat.h"

ExpItemFormat::ExpItemFormat(BExp* exp)
{
	_exp = exp;
}
ExpItemFormat::~ExpItemFormat()
{

}

void ExpItemFormat::styled(const BStyle* style)
{

}
void ExpItemFormat::changed(const BString& text)
{
	int chunk_begin = text.find('[');
	int chunk_end = text.find(']') + 1;
	BColor color = syntaxColor(_exp->syntax);
	_colorMap.insert(chunk_begin, color);
	int addr_pos = text.find("0x");
	_colorMap.insert(addr_pos, BColor(200, 0, 200));
}

const BFont* ExpItemFormat::font(int pos) const
{
	auto cit = _fontMap <= pos;
	return cit.value();
}
const BColor* ExpItemFormat::color(int pos) const
{
	auto cit = _colorMap <= pos;
	if (cit.valid())
	{
		return &cit.value();
	}
	return 0;
}

void ExpItemFormat::clear()
{
	_colorMap.clear();
	_fontMap.clear();
}

BColor ExpItemFormat::syntaxColor(Syntax syntax)
{
	switch (syntax)
	{
	case Syntax_None:
	{
		return BColor(123, 100, 86);
	}
	case Syntax_Note:
	{
		return BColor(64, 128, 64);
	}
	case Syntax_Include:
	{
		return BColor(123, 100, 86);
	}
	case Syntax_File:
	{
		return BColor(128, 10, 10);
	}
	case Syntax_Type:
	{
		return BColor(32, 64, 200);
	}
	case Syntax_Value:
	{
		return BColor(128, 10, 10);
	}
	case Syntax_Name:
	{
		return BColor(10, 30, 60);
	}
	case Syntax_Self:
	{
		return BColor(128, 32, 128);
	}
	case Syntax_Opera:
	{
		return BColor(10, 30, 60);
	}
	case Syntax_Call:
	{
		return BColor(128, 128, 32);
	}
	case Syntax_Method:
	case Syntax_Function:
	{
		return BColor(86, 156, 86);
	}
	case Syntax_If:
	case Syntax_Else:
	case Syntax_For:
	case Syntax_While:
	case Syntax_Switch:
	case Syntax_Case:
	case Syntax_Default:
	case Syntax_Continue:
	case Syntax_Break:
	case Syntax_Return:
	{
		return BColor(128, 32, 128);
	}
	case Syntax_Const:
	case Syntax_Extern:
	case Syntax_Virtual:
	case Syntax_Class:
	case Syntax_Access:
	{
		return BColor(123, 86, 200);
	}
	default:
		break;
	}
	return BColor(30, 30, 30);
}
